﻿using RPAVIEW.util;
using RPAVIEW.views.controlLibrary;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
namespace RPAVIEW.views.EditPage.flows.DateTime2TextN {
    /// <summary>
    /// Input.xaml 的交互逻辑
    /// </summary>
    public partial class Input:BaseParamViewAction{
        public Input() {
            InitializeComponent();
        }

        public override void UpdateSource() {
            this.dateObj.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.formatType.GetBindingExpression(ComboBox.SelectedIndexProperty).UpdateSource();
            this.separator.GetBindingExpression(TextBox.TextProperty).UpdateSource();
        }

        private void FormatTypeChanged(object sender, SelectionChangedEventArgs e) {
            int type = this.formatType.SelectedIndex;
            string separator = ParamUtil.GetCurrentParam<DateTime2TextNParam>().Separator;
            string fromatString;
            if(separator == null) { 
                separator = "";
            }
            switch(type) {
                case 0:
                    fromatString = DateTime.Now.ToString($"yyyy{separator}MM{separator}dd", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 1:
                    fromatString = DateTime.Now.ToString($"yyyy{separator}MM", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 2:
                    fromatString = DateTime.Now.ToString($"M{separator}dd", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 3:
                    fromatString = DateTime.Now.ToString("yyyy", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 4:
                    fromatString = DateTime.Now.Month.ToString();
                    break;
                case 5:
                    fromatString = DateTime.Now.Day.ToString();
                    break;
                default:
                    fromatString = DateTime.Now.ToString($"yyyy{separator}MM{separator}dd", DateTimeFormatInfo.InvariantInfo);
                    break;
            }
            this.example.Content = $"示例：{fromatString}";
        }

        private void SeparatorChanged(object sender, TextChangedEventArgs e) {
            int type = this.formatType.SelectedIndex;
            string separator = this.separator.Text;
            string fromatString;
            if(separator == null) { 
                separator = "";
            }
            switch(type) {
                case 0:
                    fromatString = DateTime.Now.ToString($"yyyy{separator}MM{separator}dd", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 1:
                    fromatString = DateTime.Now.ToString($"yyyy{separator}MM", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 2:
                    fromatString = DateTime.Now.ToString($"M{separator}dd", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 3:
                    fromatString = DateTime.Now.ToString("yyyy", DateTimeFormatInfo.InvariantInfo);
                    break;
                case 4:
                    fromatString = DateTime.Now.Month.ToString();
                    break;
                case 5:
                    fromatString = DateTime.Now.Day.ToString();
                    break;
                default:
                    fromatString = DateTime.Now.ToString($"yyyy{separator}MM{separator}dd", DateTimeFormatInfo.InvariantInfo);
                    break;
            }
            this.example.Content = $"示例：{fromatString}";
        }
    }
}
